﻿Imports NHibernate
Imports NHibernate.Criterion
Imports TodoMicroSolutionPackV1.dal.dao
Imports TodoMicroSolutionPackV1.entidades.dal.dto
Namespace entidades.dal.dao
    Public Class entidadDAO
        Inherits GenericNHibernateDAO(Of entidad, Integer)
        Public Function buscarCliente(ByVal razonsocial As String, ByVal numero_documento As Int64, ByVal nombre As String, ByVal apellido As String, ByVal email As String, ByVal id As Integer) As IList(Of entidad)
            Dim criteria As ICriteria = session.CreateCriteria(Of entidad)()

            If (razonsocial <> "") Then criteria.Add(Expression.Like("razon_social", razonsocial, MatchMode.Anywhere))
            If (numero_documento > 0) Then criteria.Add(Expression.Eq("numero_documento", numero_documento))
            If (nombre <> "") Then criteria.Add(Expression.Like("nombre", nombre, MatchMode.Anywhere))
            If (apellido <> "") Then criteria.Add(Expression.Like("apellido", apellido, MatchMode.Anywhere))
            If (email <> "") Then criteria.Add(Expression.Or(Expression.Or(Expression.Like("email1", email, MatchMode.Anywhere), Expression.Like("email2", email, MatchMode.Anywhere)), Expression.Like("email3", email, MatchMode.Anywhere)))
            If (id > 0) Then criteria.Add(Expression.Eq("id", id))

            criteria.CreateCriteria("tipo_entidad").Add(Expression.Eq("categoria", "entidades")) _
                .Add(Expression.Eq("tipo", "tipo")) _
                .Add(Expression.Like("codigo", "_1"))

            Return criteria.List(Of entidad)()
        End Function
        Public Sub New(ByRef session As ISession)
            MyBase.New(session)
        End Sub
    End Class
End Namespace

